/* Copyright [2023] <gyl> */

#include "sql/executor/use_executor.h"

#include "event/session_event.h"
#include "event/sql_event.h"
#include "session/session.h"
#include "sql/stmt/use_stmt.h"

RC UseExecutor::execute(SQLStageEvent *sql_event) {
  Stmt *stmt = sql_event->stmt();
  ASSERT(stmt->type() == StmtType::USE,
         "use executor can not run this command: %d",
         static_cast<int>(stmt->type()));

  UseStmt *use_stmt = static_cast<UseStmt *>(stmt);
  sql_event->session_event()->session()->set_current_db(
      use_stmt->database_name().c_str());
  return RC::SUCCESS;
}
